package com.qunar.train.mock.apache;

import org.apache.http.HttpResponse;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.fluent.Content;
import org.apache.http.client.fluent.Response;

import java.io.File;

import mockit.Mock;
import mockit.MockUp;

public class MockResponse {

    public static String VERSION = "1.0.0";

    public static ThreadLocal<MockResponse> threadLocal = new ThreadLocal<>();

    public static MockResponse getInstance() {
        if (threadLocal.get() == null) {
            threadLocal.set(new MockResponse());
        }
        return threadLocal.get();
    }

    private boolean equalsReturnValue = false;
    private Object handleResponseReturnValue = null;
    private int hashCodeReturnValue = 0;
    private org.apache.http.client.fluent.Content returnContentReturnValue = null;
    private HttpResponse returnResponseReturnValue = null;
    private String toStringReturnValue = null;

    public static void mockResponse() {
        new MockResponse.ResponseMockUp();
    }

    public static class ResponseMockUp extends MockUp<Response> {

        @Mock
        public void $init(final HttpResponse response) {
        }

        @Mock
        public void discardContent() {
        }

        @Mock
        public boolean equals(Object arg0) {
            return getInstance().equalsReturnValue;
        }

        @Mock
        public <T> T handleResponse(ResponseHandler<T> arg0) {
            return (T) getInstance().handleResponseReturnValue;
        }

        @Mock
        public int hashCode() {
            return getInstance().hashCodeReturnValue;
        }

        @Mock
        public Content returnContent() {
            return getInstance().returnContentReturnValue;
        }

        @Mock
        public HttpResponse returnResponse() {
            return getInstance().returnResponseReturnValue;
        }

        @Mock
        public void saveContent(File arg0) {
        }

        @Mock
        public String toString() {
            return getInstance().toStringReturnValue;
        }

        public static void clear() {
        }

    }

    public static void setEqualsReturnValue(boolean p) {
        getInstance().equalsReturnValue = p;
    }

    public static <T> void setHandleResponseReturnValue(T p) {
        getInstance().handleResponseReturnValue = p;
    }

    public static void setHashCodeReturnValue(int p) {
        getInstance().hashCodeReturnValue = p;
    }

    public static void setReturnContentReturnValue(org.apache.http.client.fluent.Content p) {
        getInstance().returnContentReturnValue = p;
    }

    public static void setReturnResponseReturnValue(HttpResponse p) {
        getInstance().returnResponseReturnValue = p;
    }

    public static void setToStringReturnValue(String p) {
        getInstance().toStringReturnValue = p;
    }


    public static void clear() {
        getInstance().equalsReturnValue = false;
        getInstance().handleResponseReturnValue = null;
        getInstance().hashCodeReturnValue = 0;
        getInstance().returnContentReturnValue = null;
        getInstance().returnResponseReturnValue = null;
        getInstance().toStringReturnValue = null;
    }


}
